package asia.doing.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;


@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private JwtInterceptor jwtInterceptor;

    // 加自定义拦截器JwtInterceptor，设置拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] excludePatterns = new String[]{
                // Swagger UI 和 Knife4j 相关路径
                "/swagger-ui.html",
                "/swagger-ui/**",
                "/swagger-resources/**",
                "/v3/api-docs/**",
                "/webjars/**",
                "/v2/**",
                "/api",
                "/api-docs",
                "/api-docs/**",
                "/doc.html/**",

                // 公开的 API 路径
                "/",
                "/v1/login",
                "/v1/register",
                "/files/**",
                "/favicon.ico",
                "/v1/front/**" //放开博客前台页面
        };

        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePatterns);
    }

}